import Request from './request'


export const userLoginAndReg = (url: string, data: { username: string, password: string, repassword: string }) => {
  return Request.post<{ token: string }>(url, data, { token: false })
}

export const userLogoutApi = () => {
  return Request.get('/logout', { token: true })
}

export const userGetSize = () => {
  return Request.get<{ total_size: number, used_size: number }>('/getSize', { token: true })
}

export const getFileList = (url: string) => {
  return Request.get('/file?' + url, { token: true })
}

export const postCreateDir = (data: { file_id: number, name: string }) => {
  return Request.post('/file/createDir', data, { token: true })
}

export const postRename = (data: { id: number, name: string }) => {
  return Request.post('/file/rename', data, { token: true })
}

export const postAllDelete = (ids: string) => {
  return Request.post('/file/delete', { ids }, { token: true })
}


export const getSearch = (keyword: string) => {
  return Request.get('/file/search?keyword=' + keyword, { token: true })
}


export const getDownload = (url: string) => {
  return Request.get(url, { responseType: 'blob' })
}


export const postShareCreate = (id: number) => {
  return Request.post('/share/create', {
    file_id: id
  }, { token: true })
}


export const getShareList = () => {
  return Request.get('/share/list', { token: true })
}

export const getCurrentShare = (key: string) => {
  return Request.get(`/share/${key}`)
}


export const getDirlist = () => {
  return Request.get('/file/dir', { token: true })
}

export const postSvae = (data: { dir_id: number, sharedurl: string }) => {
  return Request.post('/share/save', data, { token: true })
}